import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';

class textBook extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '通讯录',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: ContactsPage(),
    );
  }
}

class ContactsPage extends StatefulWidget {
  @override
  _ContactsPageState createState() => _ContactsPageState();
}

class _ContactsPageState extends State<ContactsPage> {
  final ScrollController _scrollController = ScrollController();

  // @override
  // void initState() {
  //   super.initState();
  //   _scrollController.addListener(_onScroll);
  // }
  //
  // @override
  // void dispose() {
  //   _scrollController.removeListener(_onScroll);
  //   _scrollController.dispose();
  //   super.dispose();
  // }
  //
  // void _onScroll() {
  //   // 当用户滚动时隐藏键盘
  //   if (_scrollController.position.userScrollDirection != ScrollDirection.idle) {
  //     _hideKeyboard();
  //   }
  // }

  void _hideKeyboard() {
    FocusScope.of(context).unfocus();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('通讯录'),
        actions: [
          IconButton(
            icon: Icon(Icons.refresh),
            onPressed: () {},
          ),
          IconButton(
            icon: Icon(Icons.person_add),
            onPressed: () {},
          ),
        ],
      ),
      body: SingleChildScrollView(
        controller: _scrollController,
        physics: BouncingScrollPhysics(),
        child: Column(
          children: [
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: TextField(
                decoration: InputDecoration(
                  prefixIcon: Icon(Icons.search),
                  hintText: '搜索',
                  border: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(10.0),
                    borderSide: BorderSide.none,
                  ),
                  filled: true,
                  fillColor: Colors.grey[200],
                ),
                textInputAction: TextInputAction.search,
                onSubmitted: (value) {
                  // 处理搜索逻辑
                  print('搜索: $value');
                },
              ),
            ),
            ListTile(
              leading: Icon(Icons.person_add, color: Colors.orange),
              title: Text('新的联系人'),
            ),
            ListTile(
              leading: Icon(Icons.favorite, color: Colors.red),
              title: Text('特别关注'),
            ),
            Divider(),
            ListTile(
              leading: Icon(Icons.contacts, color: Colors.blue),
              title: Text('辽政通通讯录'),
              subtitle: Text('(2329298人)'),
            ),
            ListTile(
              leading: Icon(Icons.business, color: Colors.green),
              title: Text('行业机构树'),
              subtitle: Text('(12930人)'),
            ),
            ListTile(
              leading: Icon(Icons.business, color: Colors.blue),
              title: Text('辽宁省营商环境建设局'),
              subtitle: Text('(120人)'),
            ),
            ListTile(
              leading: Icon(Icons.business, color: Colors.blue),
              title: Text('全面振兴新突破三年行动领导小组'),
              subtitle: Text('(120人)'),
            ),
            Divider(),
            ListView(
              shrinkWrap: true,
              // physics: NeverScrollableScrollPhysics(),
              children: [
                ListTile(
                  leading: CircleAvatar(
                    backgroundImage: NetworkImage('https://via.placeholder.com/150'),
                  ),
                  title: Text('刘洪东'),
                  subtitle: Text('辽宁省营商环境建设局'),
                ),
                ListTile(
                  leading: CircleAvatar(
                    backgroundImage: NetworkImage('https://via.placeholder.com/150'),
                  ),
                  title: Text('兰谦寒'),
                  subtitle: Text('沈阳市大数据管理中心'),
                ),
                ListTile(
                  leading: CircleAvatar(
                    backgroundImage: NetworkImage('https://via.placeholder.com/150'),
                  ),
                  title: Text('稳诗婷'),
                  subtitle: Text('鞍山市大数据管理中心'),
                ),
              ],
            ),
          ],
        ),
      ),
      bottomNavigationBar: BottomNavigationBar(
        items: [
          BottomNavigationBarItem(
            icon: Icon(Icons.message),
            label: '消息',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.work),
            label: '工作台',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.contacts),
            label: '通讯录',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.more_horiz),
            label: '更多',
          ),
        ],
        currentIndex: 2, // 通讯录是当前页面
        onTap: (index) {
          // 处理导航项点击事件
        },
      ),
    );
  }
}
